//
//  SNCache.m
//  Library
//
//  Created by stone on 16/10/14.
//  Copyright © 2016年 huogenghao. All rights reserved.
//

#import "SNCache.h"
#import "YYCache.h"

@implementation SNCache
static NSString *const SNNormalCache = @"SNNormalCache";
static YYCache *_dataCache;


+ (void)initialize
{
    _dataCache = [YYCache cacheWithName:SNNormalCache];
    //    _dataCache.memoryCache.shouldRemoveAllObjectsOnMemoryWarning = YES;
    //    _dataCache.memoryCache.shouldRemoveAllObjectsWhenEnteringBackground = YES;
}
+ (void)changeDB:(NSString *)accountId{
    _dataCache = [YYCache cacheWithName:[NSString stringWithFormat:@"%@%@",SNNormalCache,accountId]];
    NSLog(@"changeDB = %@",[NSString stringWithFormat:@"%@%@",SNNormalCache,accountId]);
}
+ (void)saveCache:(id)cache forKey:(NSString *)key
{
    //    NSLog(@"%@",key);
    //异步缓存,不会阻塞主线程
    [_dataCache setObject:cache forKey:key withBlock:nil];
}

+ (id)getCacheForKey:(NSString *)key
{
    return [_dataCache objectForKey:key];
}

+ (NSInteger)getAllCacheSize
{
    return [_dataCache.diskCache totalCost];
}

+ (void)removeAllCache
{
    [_dataCache.diskCache removeAllObjects];
    [_dataCache.memoryCache removeAllObjects];
}
+ (void)removeCacheForKey:(NSString *)key
{
    [_dataCache.diskCache removeObjectForKey:key];
    [_dataCache.memoryCache removeObjectForKey:key];
}
@end
